package com.bml.architect.netty.serialiable.codec;

import com.bml.architect.entity.User;
import com.bml.architect.util.ProtostuffUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class ProtostuffDecoder extends ByteToMessageDecoder {


    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

        int readLen = in.readableBytes();
        if(readLen > 0){
            byte [] array = new byte[readLen];
            in.readBytes(array);
            out.add(ProtostuffUtil.deserializer(array, User.class));
        }

    }
}
